﻿using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using DimsMapper.Modules;

namespace DimsMapper
{
    internal class Minimap
    {
        //internal static Point[] locator = new Point[3] { new Point(0, 0), new Point(25, 25), new Point(0, 0) };

        private Bitmap[] miniMap;
        private BitmapData data;
        private int levels;

        internal Minimap(int levels)
        {
            miniMap = new Bitmap[3];

            for (int i = 0; i < levels; i++)
            {
                AddLevel();
            }
        }

        internal void AddLevel()
        {
            miniMap[levels] = new Bitmap(100, 100, PixelFormat.Format8bppIndexed);
            miniMap[levels].Palette = FrmFiles.FrmPal.palette;
            levels++;
        }

        internal Bitmap GetLevel(int level)
        {
            return miniMap[level];
        }

        internal void Lock(int level)
        {
            data = miniMap[level].LockBits(new Rectangle(0, 0, 100, 100), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
        }

        internal void Unlock(int level)
        {
            miniMap[level].UnlockBits(data);
            data = null;
        }

        internal unsafe void SetPixel(int x, int y, byte pixel)
        {
            ((byte*)data.Scan0)[x + (y * data.Stride)] = pixel;
        }
    }
}
